package flowSum;


import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

/**
 * @author caoxiaofeng
 * @date 2021-07-14 23:25
 */
public class FlowCountReduce extends Reducer<Text, FlowBean, Text, FlowBean> {


    FlowBean v = new FlowBean();

    @Override
    protected void reduce(Text key, Iterable<FlowBean> values, Context context) throws IOException, InterruptedException {

        long sum_upFlow = 0;
        long sum_downFlow = 0;

        //1. 累加求和
        for (FlowBean flowBean : values){
            sum_downFlow += flowBean.getDownFlow();
            sum_upFlow += flowBean.getUpFlow();
        }
        //2. 写出
        v.set(sum_upFlow,sum_downFlow);
        context.write(key,v);

    }
}
